﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;
using Microhard.WarehouseInsp.Buz.Models;
using Microhard.WarehouseInsp.Buz.Msg;
using Microhard.WarehouseInsp.Buz.Interfaces;
using Microhard.Core;
using FluentValidation.Results;

namespace Microhard.WarehouseInsp.Buz.Validator
{

    public class WarehouseTransitionModelValidator : AbstractValidator<WarehouseTransitionModel>
    {
        public WarehouseTransitionModelValidator()
        {
            RuleSet("Insert", () =>
            {
                //RuleFor(u => u.TransEmployeeName).NotEmpty().WithMessage(WarehouseTransitionMsg.NeedTransEmployeeName).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);
                RuleFor(u => u.RecEmployeeName).NotEmpty().WithMessage(WarehouseTransitionMsg.NeedRecEmployeeName).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);
                RuleFor(u => u.TransEmployeeName).Length(1, 20).WithMessage(WarehouseTransitionMsg.MaxNameLength).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);
                RuleFor(u => u.RecEmployeeName).Length(1, 20).WithMessage(WarehouseTransitionMsg.MaxNameLength).When(r => r.OperationStatus == Core.DBUtility.OperationStatus.Add);

                Custom(u =>
              {
                  if (Guid.Empty==u.WarehouseID)
                  {
                      return new ValidationFailure("WarehouseID", WarehouseTransitionMsg.NeedWarehouseID);
                  }
                  return null;
              });

            });
        }
    }
}

